//
//  addBumViewController.m
//  文印室
//
//  Created by KL on 17/2/23.
//  Copyright © 2017年 KM. All rights reserved.
//

#import "AddBumViewController.h"
#import "DataChe.h"
#import "BumenView.h"
@interface AddBumViewController ()
@property (weak, nonatomic) IBOutlet UITextField *bumName;

@end

@implementation AddBumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"添加部门";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(endAdd:)];
}

- (void)endAdd:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)sureAdd:(id)sender {
    
    NSMutableString *str = [NSMutableString stringWithFormat:@"http://a.xl18z.cn/api/department/insert?"];
    NSDictionary *dic = @{
                          @"name":_bumName.text
                          };
    for (NSString *key in dic) {
        [str appendFormat:@"%@=%@",key,dic[key]];
    }
    [DataChe getWithParam:str complete:^(NSDictionary *d) {
        UIAlertController *al = [UIAlertController alertControllerWithTitle:@"提示" message:@"部门已经添加" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *a1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.bumName.text = @"";
        }];
        [al addAction:a1];
        [self presentViewController:al animated:YES completion:nil];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
